using System;
using System.Diagnostics;
using AsyncLibrary.StatusListener;

namespace AsyncLibrary
{
  public class StatusSpeaker
  {
    private bool _finitMode;
    private int _progress;

    public ListenersCollection Listeners { get; private set; }

    public StatusSpeaker(ListenersCollection listeners)
    {
      Listeners = listeners;
    }

    public void FinitMode(string message, int max)
    {
      _progress = 0;
      Listeners.SetProgresMax(max);
      Listeners.SetProgress(0);
      Listeners.SetStatus(message);
      Listeners.SetMode(StatusProgressMode.Progress);
      _finitMode = true;
    }

    public void InfinitMode(string message)
    {
      Listeners.SetStatus(message);
      Listeners.SetMode(StatusProgressMode.Infinity);
      _finitMode = false;
    }

    public void IncrementProgress()
    {
      Debug.Assert(_finitMode);
      Listeners.SetProgress(++_progress);
    }

    public void SetInfo(string additionalInfo)
    {
      Listeners.SetInfo(additionalInfo);
    }

    public void SetStatus(string additionalInfo)
    {
      Listeners.SetStatus(additionalInfo);
    }

    public void FatalError(Exception message)
    {
      Listeners.FatalError(message);
      _finitMode = false;
    }
  }
}